import functools
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon
import sys


def on_state_changed(pos, arg):
    print("pos: ", pos)
    if arg == Qt.Checked:
        print("选中")
    else:
        print("未选中")


if __name__ == '__main__':
    # 1.创建应用程序
    app = QApplication(sys.argv)

    # 2.创建窗口
    w = QWidget()

    w.resize(400, 300)

    # 修改窗口标题
    w.setWindowTitle('多选框')

    btn1 = QCheckBox("抽烟")
    btn2 = QCheckBox("喝酒")
    btn3 = QCheckBox("烫头")
    btn1.setChecked(True)
    btn1.stateChanged.connect(lambda arg: on_state_changed(1, arg))
    btn2.stateChanged.connect(lambda arg: on_state_changed(2, arg))
    btn3.stateChanged.connect(functools.partial(on_state_changed, 3))

    # 添加到w中
    layout = QHBoxLayout()
    layout.addWidget(QLabel("谦哥的三大爱好："))
    layout.addWidget(btn1)
    layout.addWidget(btn2)
    layout.addWidget(btn3)
    w.setLayout(layout)

    # 3.显示窗口
    w.show()

    # 4.等待窗口停止
    sys.exit(app.exec())
